package com.kkb.mybatis.framework.parser;

import com.kkb.mybatis.framework.sqlsource.SqlSource;
import com.kkb.mybatis.framework.sqlsource.StaticSqlSource;
import com.kkb.mybatis.utils.GenericTokenParser;
import com.kkb.mybatis.utils.ParameterMappingTokenHandler;

/**
 *  用于处理#{} , 获取StaticSqlSource
 */
public class SqlSourceParser {

    public SqlSource parse(String sqlText){
        //处理#{}   生成parameterMappings
        ParameterMappingTokenHandler tokenHandler = new ParameterMappingTokenHandler();
        GenericTokenParser genericTokenParser = new GenericTokenParser("#{", "}",tokenHandler);
        String sql = genericTokenParser.parse(sqlText);
        return new StaticSqlSource(sql,tokenHandler.getParameterMappings());
    }
}
